Now that we have a file containing the data that represents our network, we just need to load it and graph it. First, run the cell below by clicking on it and hitting Ctrl-Enter
to import all of the utilities we need. You can reach each cell after this one by doing the same thing.
In [ ]:
import wikinetworking as wn
import networkx as nx
import matplotlib.pyplot as plt
from pyquery import PyQuery
%matplotlib inline
print "OK"
Let's pick the filename that contains our graph data.
In [ ]:
filename = "FILL_IN_A_FILENAME.json"
Now we can create the graph and draw it. Run the cell below to see the graph. You can try playing around with different ways of representing the graph. Try changing the following options in the code below and then re-running the cell:
minimum_weight
: The minimum number of links between two articlese before a line will be drawn between themcmap
: The range of colors for nodes. You can choose any color map in the matplotlib colormap reference. The nodes are colored based on their degree, or the number of neighbors a node hasedge_cmap
: The range of colors for edges that connect nodes. The edges are colored based on their weight, which is (in this case) the number of links between two neighbors.You may also try changing the minimum_weight
parameter for wn.create_graph
. Changing the minimum weight for displaying a relationship creates different clusterings of articles.
In [ ]:
network = wn.load_dict(filename)
graph = wn.create_graph(network, minimum_weight=1)
layout = nx.spring_layout(graph)
graph_html = wn.make_interactive_graph(graph, pos=layout, cmap=plt.cm.viridis, edge_cmap=plt.cm.Reds)
In [ ]:
wn.save_big_graph(graph, pos=layout, cmap=plt.cm.viridis, edge_cmap=plt.cm.YlOrBr, font_size=1, node_size_factor=5,dpi=800)